package com.wbdca.crawler.util;

import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;

public class CrawlerUtil {
    public static String trim(String str){
        if(str.startsWith("\"") && str.endsWith("\"")){
            return str.substring(1, str.length()-1);
        } else if (str.endsWith("null")) {
            return null;
        }
        return str;
    }

    /**
     * Handles URISyntaxException.
     * @param address
     * @return
     * @throws URISyntaxException
     * @throws MalformedURLException
     */
    public static URI getURI(String address) throws URISyntaxException, MalformedURLException {
        URL url = new URL(address);
        String nullFragment = null;
        URI uri = new URI(url.getProtocol(), url.getHost(), url.getPath(), url.getQuery(), nullFragment);
        return uri;
    }
}
